const Router = require("koa-router");
const http = require("../utils/http.js");

const router = new Router({
    prefix: "/product"
});

router.post("/list", async(ctx, next) => {
    let {
        name,
        cid,
        orderCol,
        orderDir,
        begin,
        pageSize
    } = ctx.request.body;

    let sql = "call p_getProduct(?,?,?,?,?,?);"; //执行存储过程 获得的数据外面会多有一个[]
    let results = await http(sql, [name,
        cid,
        orderCol,
        orderDir,
        begin,
        pageSize
    ]);
    console.log(results);
    return Promise.resolve(results[0]);
});
router.get("/model/:id", async(ctx, next) => {
    let id = parseInt(ctx.params.id);
    let sql = "select * from `dt_product` where `id` = ?;";
    let results = await http(sql, [id]);
    return Promise.resolve(results[0]);
});


module.exports = router.routes();